Do you thing that all objects of the same type are the same size?

A good answer might be:

No. Objects are bigger and more complicated than primitive data types. It would be too restrictive if all objects of the same type had to be the same size.

A String Object

Objects are big, complicated, and vary in size. You DO NOT automatically get an object when you declare an object reference variable. All you get is a name for a future object. Examine the following:


class egString
{

  public static void main ( String[] args )
  {
    String str;
    
    str = new String( "The Gingham Dog" );

    System.out.println( str );
  }
}

An object contains data and methods (state and behavior). You can visualize the String object in the above program like this:

The data section of the object contains the characters. The methods section of the object contains many methods. (Actually, this picture is a simplification. The Java system does something more efficient, but logically equivalent.) In future diagrams showing objects, the methods of the object will usually not be shown.

QUESTION 4:

(Review:) What does the following new do?

   
str = new String( "The Gingham Dog" );